package com.up.stores.controller;

import com.up.stores.entity.Collection;
import com.up.stores.service.ICollectionService;
import com.up.stores.until.JsonResult;
import com.up.stores.vo.CollectionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Api(tags="收藏夹模块")
@RequestMapping("collections")
@RestController
public class CollectionController extends BaseController {
    @Autowired
    private ICollectionService collectionService;

    @ApiOperation(value="添加收藏夹")
    @PostMapping("add_Collection")
    public JsonResult<Void> addCollection(Integer pro_id, HttpSession session) {
        Integer uid = getuidFromSession(session);
        String type = getTypeFromSession(session);
        collectionService.addCollection(uid, type, pro_id);
        return new JsonResult<>(OK);
    }

    @ApiOperation(value="收藏夹删除")
    @DeleteMapping("delete_Collection")
    public JsonResult<Void> deleteCollection(Integer colId) {
        collectionService.deleteCollection(colId);
        return new JsonResult<>(OK);
    }

    @ApiOperation(value="获取当前用户的收藏夹信息")
    @GetMapping("get_Collection")
    public JsonResult<List<CollectionVO>> getCollection(HttpSession session) {
        Integer uid = getuidFromSession(session);
        String type = getTypeFromSession(session);
        List<CollectionVO> list =  collectionService.getCollection(uid, type);
        return new JsonResult<>(OK, list);
    }

}
